package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// RoleAuthRule 角色权限映射
type RoleAuthRule struct {
	ID        string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	RoleID    string `json:"role_id" gorm:"column:role_id;type:int;size:64;index:idx_role_rule,unique;comment:角色id"`
	RuleID    string `json:"rule_id" gorm:"column:rule_id;type:int;size:64;index:idx_role_rule,unique;comment:规则id"`
	CreatedAt int64  `json:"created_at" gorm:"autoCreateTime;column:created_at;type:int;size:64;comment:创建时间"`
	DeleteAt  int64  `json:"deleted_at" gorm:"column:deleted_at;type:int;size:64;index;default:null;comment:删除时间"`
}

// TableName 表名称
func (rr *RoleAuthRule) TableName() string {
	return "role_auth_rule"
}

// BeforeCreate 自增id
func (rr *RoleAuthRule) BeforeCreate(tx *gorm.DB) (err error) {
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	rr.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &RoleAuthRule{})
}
